package plugin

import (
	"gitee.com/mkwchecking/k-scaffold/config"
	"gitee.com/mkwchecking/k-scaffold/pkg/rely/redis"
	goredis "github.com/go-redis/redis/v8"
)

var _redis *goredis.Client

func (p *Plugins) GetRedis() (*goredis.Client, error) {
	if _redis != nil {
		return _redis, nil
	}

	redisOpt, err := config.GetDefaultRedis()
	if err != nil {
		return nil, err
	}

	redisCli, err := redis.New(p.Ctx(), redisOpt)
	if err != nil {
		return nil, err
	}

	_redis = redisCli
	return _redis, nil
}
